﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace Microsoft.Practices.Repository
{
    /// <summary>
    /// Used to indicate that a value returned from the 
    /// database was null or empty and that it could not
    /// be handled.
    /// </summary>
    [Serializable]
    [SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")]
    public class DBValueNullException : RepositoryException
    {
        /// <summary>
        /// Default Constructor
        /// </summary>
        public DBValueNullException() : base() { }

        /// <summary>
        /// Constructor that uses fieldName to build the exception message
        /// </summary>
        /// <param name="fieldName">built into exception message</param>
        public DBValueNullException(string fieldName)
            : base(BuildExceptionMessage(fieldName, string.Empty)) { }

        /// <summary>
        /// Constructor that uses fieldName and message to build the exception message
        /// </summary>
        /// <param name="fieldName">built into exception message</param>
        /// <param name="message">added to fieldName based message</param>
        public DBValueNullException(string fieldName, string message)
            : base(BuildExceptionMessage(fieldName, message)) { }


        private static string BuildExceptionMessage(string fieldName, string extraMessage)
        {
            return string.Format(CultureInfo.CurrentCulture, 
                "Field: {0} was empty. {1}", fieldName, extraMessage);
        }

    }
}
